/*
 * Main.cpp
 *
 *  Created on: Mar 30, 2011
 *      Author: s88900
 */
#include "Generator.h"
#include "Camera.h"
#include "Merger.h"
#include "IOController.h"
#include "ImageBuffer.h"
#include "Panorama.h"
#include "Sender.h"

int main() {
	Generator* generator = new Generator();
	generator->start();

	ImageBuffer *ibuffer = new ImageBuffer();
	PanoramaBuffer *pbuffer = new PanoramaBuffer();

	Panorama* p = new Panorama(ibuffer, pbuffer);
	p->start();

	Sender* s = new Sender(pbuffer);
	s->start();

	Merger* mergers[3];
	for (int i = 0; i < 3; i++) {
		IOController *ioc = new IOController(i, ibuffer);
		mergers[i] = new Merger(i, ioc);
		mergers[i]->start();
	}

	Camera* cams[9];
	for (int i = 0; i < 9; i++) {
		int x = i;
		while (x > 2) {
			x -= 3;
		}
		//cout << "cam: " << i << " gekoppeld aan merger: " << x << endl;
		cams[i] = new Camera(i, generator, mergers[x]);
		cams[i]->start();
		usleep(7500);
	}
	sleep(100);
	delete generator;
	delete ibuffer;
	delete pbuffer;
	delete p;
	delete s;

	for (int i = 0; i < 3; i++) {
		delete mergers[i];
		mergers[i] = 0;
	}

	for (int i = 0; i < 9; i++) {
		delete cams[i];
		cams[i] = 0;
	}

	return 0;
}
